local t = Def.ActorFrame {}
local Idx, Bpm, ReadBpm

--Adornos
t[#t+1] = LoadActor("_ARR");
t[#t+1] = LoadActor("_OV");

--cargar luas con parámetros (como si fuera una funcion)
--diff P1
t[#t+1] = LoadActor("_difficulty",PLAYER_1)..{
	InitCommand=function(self)
		local sides = GAMESTATE:GetNumSidesJoined()
		self:x(sides == 1 and SCREEN_CENTER_X or SCREEN_CENTER_X-80);
		self:y(82);
	end;
	PlayerJoinedMessageCommand=cmd(playcommand,"Init");
}

--diff P2
t[#t+1] = LoadActor("_difficulty",PLAYER_2)..{
	InitCommand=function(self)
		local sides = GAMESTATE:GetNumSidesJoined()
		self:x(sides == 1 and SCREEN_CENTER_X or SCREEN_CENTER_X+80);
		self:y(82);
	end;
	PlayerJoinedMessageCommand=cmd(playcommand,"Init");
}

--Meter+Meterbar P1
t[#t+1] = LoadActor("_meterbar",PLAYER_1)..{
	InitCommand=function(self)
		local sides = GAMESTATE:GetNumSidesJoined()
		self:x(sides == 1 and SCREEN_CENTER_X or SCREEN_CENTER_X-10);
		self:y(SCREEN_BOTTOM-75);
		--self:horizalign(sides == 1 and center or right);
	end;
	PlayerJoinedMessageCommand=cmd(playcommand,"Init");
}

--Meter+Meterbar P2
t[#t+1] = LoadActor("_meterbar",PLAYER_2)..{
	InitCommand=function(self)
		local sides = GAMESTATE:GetNumSidesJoined()
		self:x(sides == 1 and SCREEN_CENTER_X or SCREEN_CENTER_X+10);
		self:y(SCREEN_BOTTOM-75);
		--self:horizalign(sides == 1 and center or left);
	end;
	PlayerJoinedMessageCommand=cmd(playcommand,"Init");
}

--songtitle
--yupi! se ven de uno por uno: Título - Intérprete - Bpm - Grupo; con fades :P
t[#t+1] = LoadFont("ArialOutline")..{
	InitCommand=cmd(shadowlength,0;zoom,0.8;x,SCREEN_CENTER_X;y,140);
	CurrentSongChangedMessageCommand=function(self)
		Idx = 1
		ReadBpm = 0
		self:stoptweening();
		if not GAMESTATE:GetCurrentSong() then
			(cmd(linear,0.2;diffusealpha,0))(self);
			return
		end
		self:diffusealpha(0);
		self:queuecommand("Loop");
	end;
	LoopCommand=function(self)
		--leer el Bpm a la segunda vez que se haga el ciclo
		--(si lo hace la primera vez leerá el bps del sonido de fondo)
		if ReadBpm <= 1 then
			Bpm = GAMESTATE:GetSongBPS() * 60
		end
		
		ReadBpm = ReadBpm+1
		-- ReadBpm max = 2. No quiero que ReadBpm valga más de 2
		if ReadBpm > 2 then
			ReadBpm = 2
		end
		
		local songinfos = {
			GAMESTATE:GetCurrentSong():GetDisplayFullTitle();
			GAMESTATE:GetCurrentSong():GetDisplayArtist();
			string.format("BPM: %.2f",Bpm);
			string.upper(GAMESTATE:GetCurrentSong():GetGroupName());
		}
		if Idx > #songinfos then Idx = 1 end
		self:settext(songinfos[Idx]);
		Idx = Idx+1
		
		(cmd(linear,0.2;diffusealpha,1;sleep,1.5;linear,0.2;diffusealpha,0))(self);
		--otra vez
		self:queuecommand("Loop");
	end;
	--deja de ejecutar el comando para ir rápido a la siguiente pantalla
	OffCommand=cmd(stoptweening); --;linear,0.2;diffusealpha,0);
}

--OpsList Background
for player in ivalues(PlayerNumber) do
t[#t+1] = Def.Quad {
	InitCommand=function(self)
		(cmd(y,SCREEN_CENTER_Y;zoomto,160,SCREEN_WIDTH;diffuse,0,0,0,0;fadeleft,0.1;faderight,0.1))(self);
		self:x(player == PLAYER_1 and 120 or SCREEN_WIDTH-120);
	end;
	OptionsListOpenedMessageCommand=function(self,params)
		if params.Player == player then
			(cmd(stoptweening;diffusealpha,0;linear,0.2;diffusealpha,0.5))(self)
		end
	end;
	OptionsListClosedMessageCommand=function(self,params)
		if params.Player == player then
			(cmd(stoptweening;diffusealpha,0.5;linear,0.2;diffusealpha,0))(self)
		end
	end;
}
end

--stagemeter ala Nx, Nx2, NxA Special Zone
--(más como el del worldmax :P)
t[#t+1] = LoadActor("StageMeter")..{ InitCommand=cmd(x,SCREEN_CENTER_X); };

--[[sordera plz x_x
t[#t+1] = Def.Actor { OnCommand=function() SOUND:DimMusic(0.01,2) end; }
]]

return t